import time
from distutils.command.check import check
from pickletools import long1
from time import sleep

from Tools.scripts.cleanfuture import dryrun
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By

from common.com import forum, Driver
#帖子详情页面的测试
class pContent:
    # url = ""
    driver = ""
    def __init__(self):
        # self.url = "http://127.0.0.1:9580/index.html"
        self.driver = forum.driver
        # self.driver.get(self.url)

    #检查页面元素
    def pCheck(self):
        #选择C++板块的帖子进行测试
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(3) > a").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        #帖子详情页面的元素进行查找
        #发布人
        self.driver.find_element(By.CSS_SELECTOR,"#article_details_author_name")
        #发布时间
        self.driver.find_element(By.CSS_SELECTOR,"#details_article_createTime")
        #帖子的标题
        self.driver.find_element(By.CSS_SELECTOR, "#details_article_title")
        time.sleep(1)
        #评论区列表
        text = self.driver.find_element(By.CSS_SELECTOR, "#details_article_reply_content_59").text
        print(text)

        #评论输入框
        self.driver.find_element(By.CSS_SELECTOR, "#article_details_reply > div.CodeMirror.cm-s-default.CodeMirror-wrap > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div.CodeMirror-activeline > pre")
        #评论发布按钮
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_article_reply")
        #点赞按钮
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_like_count")


    #功能测试
    def pFunTest(self):
        #测试用例一：编辑一个评论进行发布
        #发送一个评论看是否在列表中正常显示
        # #找到评论编辑框进行输入
        # self.driver.find_element(By.CSS_SELECTOR,"#article_details_reply > div.editormd-toolbar > div > ul > li:nth-child(12)").click()
        # #找到回复按钮点击进行回复
        # time.sleep(2)
        # self.driver.find_element(By.CSS_SELECTOR, "#details_btn_article_reply").click()

        #测试用例二：对帖子内容不进行编辑直接发布
        # 使用Actions链模拟点击
        time.sleep(1)
        element = self.driver.find_element(By.ID, "details_btn_article_reply")
        ActionChains(self.driver).move_to_element(element).click().perform()
        #查找提示框

        text1 = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div").text
        #打印验证
        print(text1)
        #进行截图验证
        forum.getscreenshot()

        #对点赞功能进行测试
        #寻找点赞按钮并点击
        time.sleep(1)
        element1 = self.driver.find_element(By.ID, "details_btn_like_count")
        ActionChains(self.driver).move_to_element(element1).click().perform()
        #检查提示框
        text2 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right").text
        print(text2)

        time.sleep(1)
        # 进行截图验证
        forum.getscreenshot()


# pcontent = pContent()
# pcontent.pCheck()
# pcontent.pFunTest()